package org.whh.exception;

import cn.hutool.core.util.StrUtil;
import org.whh.exception.BusinessException;


import java.sql.Connection;
import java.util.Collection;

public class WhhAssert {
    public static void isBlank(String str,String message){
        if (!StrUtil.isBlankIfStr(str)){
            throw new BusinessException(message);
        }
    }
    public static void isNotBlank(String str,String message){
        if (StrUtil.isBlankIfStr(str)){
            throw new BusinessException(message);
        }
    }

    public static void isNull(Object obj,String message){
        if (obj!=null){
            throw new BusinessException(message);
        }
    }

    public static void isNotNull(Object obj,String message){
        if (obj==null){
            throw new BusinessException(message);
        }
    }

    public static void isNull(Collection objs, String message){
        if (!(objs==null||objs.size()<1)){
            throw new BusinessException(message);
        }
    }

    public static void isNotNull(Collection objs, String message){
        if (objs==null||objs.size()<1){
            throw new BusinessException(message);
        }
    }
    public static void isTrue(boolean exp,String message){
        if (!exp){
            throw new BusinessException(message);
        }
    }
    public static void isFalse(boolean exp,String message){
        if (!exp){
            throw new BusinessException(message);
        }
    }

    public static void isEqual(String str1,String str2,String message){
        if (!str1.equals(str2))
            throw new BusinessException(message);
    }
    public static void isEqual(String str1,String str2,ErrorCode errorCode){
        if (!str1.equals(str2))
            throw new BusinessException(errorCode.getMessage());
    }


    public static void isBlank(String str,ErrorCode errorCode){
        if (!StrUtil.isBlankIfStr(str))
            throw new BusinessException(errorCode.getMessage(),errorCode.getCode());
    }

    public static void isNotBlank(String str,ErrorCode errorCode){
        if (StrUtil.isBlankIfStr(str))
            throw new BusinessException(errorCode.getMessage(),errorCode.getCode());
    }



    public static void isNull(Object obj, ErrorCode errorCode){
        if (obj!=null)
            throw new BusinessException(errorCode.getMessage(),errorCode.getCode());
    }

    public static void isNotNull(Object obj, ErrorCode errorCode){
        if (obj==null)
            throw new BusinessException(errorCode.getMessage(),errorCode.getCode());
    }


    public static void isNull(Collection objs, ErrorCode errorCode){  //null [] [1]
        if (!(objs==null || objs.size()<1))
            throw new BusinessException(errorCode.getMessage(),errorCode.getCode());
    }




    public static void isNotNull(Collection objs, ErrorCode errorCode){  //null [] [1]
        if (objs==null || objs.size()<1)
            throw new BusinessException(errorCode.getMessage(),errorCode.getCode());
    }


    public static void isTrue(boolean exp, ErrorCode errorCode){  //null [] [1]
        if (!exp)
            throw new BusinessException(errorCode.getMessage(),errorCode.getCode());
    }


    public static void isFalse(boolean exp, ErrorCode errorCode){  //null [] [1]
        if (exp)
            throw new BusinessException(errorCode.getMessage(),errorCode.getCode());
    }


    public static void isEq(String str1,String str2 , ErrorCode errorCode){  //null [] [1]
        if (!str1.equals(str2))
            throw new BusinessException(errorCode.getMessage(),errorCode.getCode());
    }
}
